this.BX=this.BX||{};(function(e,t,n,o,a,i,l,s,r,c){"use strict";function d(e){return!!e&&!!e.querySelector(".block-wrapper")}function u(e){return!!e&&!!e.querySelector('button[data-id="insert_first_block"]')}function f(e,t){return new Promise((function(n){var o=function o(a){if(!t||a.animationName===t){n(a);r.Event.bind(e,"animationend",o)}};r.Event.bind(e,"animationend",o)}))}function k(e){if(r.Type.isNil(e)){return true}if(r.Type.isArrayLike(e)){return!e.length}if(r.Type.isObject(e)){return Object.keys(e).length<=0}return true}function h(e,t){b(e,t);t.add(e)}function m(e,t,n){b(e,t);t.set(e,n)}function b(e,t){if(t.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function g(e,t,n){if(!t.has(e)){throw new TypeError("attempted to get private field on non-instance")}return n}var v=new WeakMap;var B=new WeakMap;var p=new WeakMap;var y=new WeakMap;var C=new WeakMap;var E=new WeakMap;var w=new WeakSet;var L=new WeakSet;var P=new WeakSet;var T=new WeakSet;var S=function(){function e(){babelHelpers.classCallCheck(this,e);h(this,T);h(this,P);h(this,L);h(this,w);m(this,v,{writable:true,value:{mode:"mode",register:"register",changeState:"changestate",editorEnable:"editorenable",showControls:"showcontrols",showBlockControls:"showblockcontrols",hideAll:"hideall",backendAction:"backendaction"}});m(this,B,{writable:true,value:-1});m(this,p,{writable:true,value:false});m(this,y,{writable:true,value:false});m(this,C,{writable:true,value:0});m(this,E,{writable:true,value:[]});if(H.isExternalControlsEnabled()){g(this,w,A).call(this)}}babelHelpers.createClass(e,[{key:"onBackendAction",value:function e(t,n){babelHelpers.classPrivateFieldSet(this,y,false);this.postExternalCommand(babelHelpers.classPrivateFieldGet(this,v).backendAction,{action:t,data:n})}},{key:"isControlsExternal",value:function e(){return r.Dom.hasClass(document.body,"landing-ui-external-controls")}},{key:"recalculateTops",value:function e(t){var n=this;babelHelpers.classPrivateFieldSet(this,E,[]);if(t){babelHelpers.classPrivateFieldSet(this,B,-1)}babelHelpers.toConsumableArray(document.body.querySelectorAll(".block-wrapper")).map((function(e){var t=e.getBoundingClientRect();if(t.height>1){babelHelpers.classPrivateFieldGet(n,E).push({blockId:parseInt(e.getAttribute("data-id")),top:t.top,height:t.height})}}));this.onMobileMouseMove(babelHelpers.classPrivateFieldGet(this,C))}},{key:"recalculateTopsIfExternals",value:function e(t){if(this.isControlsExternal()){this.recalculateTops(t)}}},{key:"onMobileMouseMove",value:function e(t){if(babelHelpers.classPrivateFieldGet(this,y)||!this.isControlsExternal()){return}if(t<=0){babelHelpers.classPrivateFieldSet(this,B,-1);return}babelHelpers.classPrivateFieldSet(this,C,t);for(var n=0,o=babelHelpers.classPrivateFieldGet(this,E).length;n<o;n++){if(t>=babelHelpers.classPrivateFieldGet(this,E)[n]["top"]&&(!babelHelpers.classPrivateFieldGet(this,E)[n+1]||t<babelHelpers.classPrivateFieldGet(this,E)[n+1]["top"])){if(babelHelpers.classPrivateFieldGet(this,E)[n]["top"]!==babelHelpers.classPrivateFieldGet(this,B)){babelHelpers.classPrivateFieldSet(this,B,babelHelpers.classPrivateFieldGet(this,E)[n]["top"]);this.postExternalCommand(babelHelpers.classPrivateFieldGet(this,v).showControls,{blockId:babelHelpers.classPrivateFieldGet(this,E)[n]["blockId"],top:babelHelpers.classPrivateFieldGet(this,E)[n]["top"],height:babelHelpers.classPrivateFieldGet(this,E)[n]["height"]})}break}}}},{key:"postExternalCommand",value:function e(t,n){if(window.parent){window.parent.postMessage({action:t,payload:n},window.location.origin)}}},{key:"listenExternalCommands",value:function e(t,n){var o=this;var a=BX.Landing.PageObject.getBlocks().get(n!==null&&n!==void 0&&n.blockId?n.blockId:-1);if(n!==null&&n!==void 0&&n.blockId&&!a){return}var i=function e(){setTimeout((function(){babelHelpers.classPrivateFieldSet(o,C,0);o.recalculateTops()}),300)};switch(t){case"onDesignerBlockClick":{a.onDesignerBlockClick();break}case"onEditBlockClick":{a.onShowContentPanel();break}case"onStyleBlockClick":{a.onStyleShow();break}case"onSortDownBlockClick":{a.moveDown();i();break}case"onSortUpBlockClick":{a.moveUp();i();break}case"onRemoveBlockClick":{a.deleteBlock();break}case"onChangeStateBlockClick":{a.onStateChange();break}case"onCutBlockClick":{H.getInstance().onCutBlock.bind(H.getInstance(),a)();break}case"onCopyBlockClick":{H.getInstance().onCopyBlock.bind(H.getInstance(),a)();break}case"onPasteBlockClick":{H.getInstance().onPasteBlock.bind(H.getInstance(),a,(function(e){setTimeout((function(){g(o,T,X).call(o,e)}),300)}))();break}case"onFeedbackClick":{a.showFeedbackForm();break}case"onSaveInLibraryClick":{a.saveBlock();break}case"onHideEditorPanel":{BX.Landing.UI.Panel.EditorPanel.getInstance().hide();break}}}}]);return e}();function A(){var e=this;setTimeout((function(){g(e,P,I).call(e)}),0);window.addEventListener("message",(function(t){if(e.isControlsExternal()){e.listenExternalCommands(t.data.action,t.data.payload)}}));document.addEventListener("mouseenter",(function(t){babelHelpers.classPrivateFieldSet(e,p,true)}));document.addEventListener("mouseleave",(function(t){babelHelpers.classPrivateFieldSet(e,p,false)}));document.addEventListener("mousemove",(function(t){e.onMobileMouseMove(t.y)}));document.addEventListener("scroll",(function(){if(babelHelpers.classPrivateFieldGet(e,p)){e.recalculateTopsIfExternals()}}));BX.addCustomEvent("BX.Landing.Main:changeControls",(function(t,n){if(t==="internal"){e.postExternalCommand(babelHelpers.classPrivateFieldGet(e,v).hideAll,{})}else{setTimeout((function(){e.recalculateTops(true)}),400)}}));BX.addCustomEvent("BX.Landing.Editor:enable",(function(){babelHelpers.classPrivateFieldSet(e,y,true);if(e.isControlsExternal()){e.postExternalCommand(babelHelpers.classPrivateFieldGet(e,v).hideAll,{})}}));BX.addCustomEvent("BX.Landing.Editor:disable",(function(){babelHelpers.classPrivateFieldSet(e,y,false);e.recalculateTopsIfExternals(true)}));BX.addCustomEvent("BX.Landing.Block:onAfterAdd",(function(t){setTimeout((function(){var n=t.getData();g(e,T,X).call(e,n.id)}),500)}));BX.addCustomEvent("BX.Landing.Block:changeState",(function(t,n){e.postExternalCommand(babelHelpers.classPrivateFieldGet(e,v).changeState,{blockId:t,state:n})}));BX.addCustomEvent("BX.Landing.Block:onFormSettingsOpen",(function(){if(e.isControlsExternal()){e.postExternalCommand(babelHelpers.classPrivateFieldGet(e,v).hideAll,{})}babelHelpers.classPrivateFieldSet(e,y,true)}));BX.addCustomEvent("BX.Landing.Block:onFormSettingsClose",(function(t){setTimeout((function(){babelHelpers.classPrivateFieldSet(e,y,false);e.recalculateTopsIfExternals(true)}),400);e.postExternalCommand(babelHelpers.classPrivateFieldGet(e,v).hideAll,{})}));BX.addCustomEvent("BX.Landing.Block:onAfterFormSave",(function(t){setTimeout((function(){e.postExternalCommand(babelHelpers.classPrivateFieldGet(e,v).backendAction,{action:"Landing\\Block::saveForm",data:{block:t}})}),1e3)}));BX.addCustomEvent("BX.Landing.Block:onBlockEditClose",(function(){babelHelpers.classPrivateFieldSet(e,y,false);e.recalculateTopsIfExternals(true)}));BX.addCustomEvent("BX.Landing.Block:onContentSave",this.recalculateTopsIfExternals.bind(this));BX.addCustomEvent("BX.Landing.Block:onDesignerBlockSave",this.recalculateTopsIfExternals.bind(this));BX.addCustomEvent("BX.Landing.Block:Card:add",this.recalculateTopsIfExternals.bind(this));BX.addCustomEvent("BX.Landing.Block:Card:remove",this.recalculateTopsIfExternals.bind(this));BX.addCustomEvent("BX.Landing.Block:afterRemove",this.recalculateTopsIfExternals.bind(this));BX.addCustomEvent("BX.Landing.Backend:action",this.onBackendAction.bind(this));BX.addCustomEvent("BX.Landing.Backend:batch",this.onBackendAction.bind(this))}function D(e){return{id:parseInt(e.id),state:e.isEnabled(),permissions:{allowDesignBlock:e.isDesignBlockAllowed(),allowModifyStyles:e.isStyleModifyAllowed(),allowEditContent:e.isEditBlockAllowed(),allowSorting:e.isEditBlockAllowed(),allowRemove:e.isRemoveBlockAllowed(),allowChangeState:e.isChangeStateBlockAllowed(),allowPaste:e.isPasteBlockAllowed(),allowSaveInLibrary:e.isSaveBlockInLibraryAllowed()}}}function I(){var e=this;var t=BX.Landing.PageObject.getBlocks();var n=[];babelHelpers.toConsumableArray(t).map((function(t){return n.push(g(e,L,D).call(e,t))}));this.postExternalCommand(babelHelpers.classPrivateFieldGet(this,v).register,{blocks:n})}function X(e){var t=BX.Landing.PageObject.getBlocks().get(e);if(t){this.postExternalCommand(babelHelpers.classPrivateFieldGet(this,v).register,{blocks:[g(this,L,D).call(this,t)]});if(this.isControlsExternal()){this.recalculateTops()}else{this.postExternalCommand(babelHelpers.classPrivateFieldGet(this,v).hideAll,{})}}}var F;BX.Landing.getMode=function(){return"edit"};var H=function(e){babelHelpers.inherits(t,e);babelHelpers.createClass(t,null,[{key:"getMode",value:function e(){return"edit"}},{key:"createInstance",value:function e(t){var n=BX.Landing.PageObject.getRootWindow();n.BX.Landing.Main.instance=new BX.Landing.Main(t)}},{key:"getInstance",value:function e(){var n=BX.Landing.PageObject.getRootWindow();n.BX.Reflection.namespace("BX.Landing.Main");if(n.BX.Landing.Main.instance){return n.BX.Landing.Main.instance}n.BX.Landing.Main.instance=new t(-1);return n.BX.Landing.Main.instance}},{key:"isEditorMode",value:function e(){return r.Dom.hasClass(document.body,"landing-editor")}},{key:"isExternalControlsEnabled",value:function e(){return r.Dom.hasClass(document.body,"enable-external-controls")}},{key:"topInPercent",value:function e(){var t=Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight);var n=document.documentElement.scrollTop||document.body.scrollTop;return n/t*100}}]);function t(e){var o;babelHelpers.classCallCheck(this,t);o=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this));o.setEventNamespace("BX.Landing.Main");var a=n.Env.getInstance().getOptions();o.id=e;o.options=Object.freeze(a);o.blocks=o.options.blocks;o.currentBlock=null;o.isDesignBlockModeFlag=o.options["design_block"]===true;o.loadedDeps={};o.cache=new r.Cache.MemoryCache;o.externalControls=new S;o.onSliderFormLoaded=o.onSliderFormLoaded.bind(babelHelpers.assertThisInitialized(o));o.onBlockDelete=o.onBlockDelete.bind(babelHelpers.assertThisInitialized(o));BX.addCustomEvent("Landing.Block:onAfterDelete",o.onBlockDelete);o.adjustEmptyAreas();BX.Landing.UI.Panel.StatusPanel.setLastModified(a.lastModified);if(!o.isDesignBlockModeFlag){BX.Landing.UI.Panel.StatusPanel.getInstance().show()}var i=n.Env.getInstance().getType();if(i===t.TYPE_KNOWLEDGE||i===t.TYPE_GROUP){var l=document.querySelector(".landing-main");if(r.Type.isDomNode(l)){r.Dom.addClass(l,"landing-ui-collapse")}}return o}babelHelpers.createClass(t,[{key:"isCrmFormPage",value:function e(){return n.Env.getInstance().getOptions().specialType==="crm_forms"}},{key:"isDesignBlockMode",value:function e(){return this.isDesignBlockModeFlag}},{key:"getSaveBlockPanel",value:function e(){var t=new i.SaveBlock("save_block_panel",{block:this.currentBlock});t.layout.hidden=true;t.content.hidden=false;r.Dom.append(t.layout,window.parent.document.body);return t}},{key:"getBlocksPanel",value:function e(){var t=this;return this.cache.remember("blockPanel",(function(){var e=t.createBlocksPanel();setTimeout((function(){if(e.sidebarButtons.get(t.options.default_section)){e.sidebarButtons.get(t.options.default_section).layout.click()}else{babelHelpers.toConsumableArray(e.sidebarButtons)[0].layout.click()}}));e.layout.hidden=true;e.content.hidden=false;r.Dom.append(e.layout,window.parent.document.body);return e}))}},{key:"hideBlocksPanel",value:function e(){if(this.getBlocksPanel()){return this.getBlocksPanel().hide()}return Promise.resolve()}},{key:"getLayoutAreas",value:function e(){return this.cache.remember("layoutAreas",(function(){return[].concat(babelHelpers.toConsumableArray(document.body.querySelectorAll(".landing-header")),babelHelpers.toConsumableArray(document.body.querySelectorAll(".landing-sidebar")),babelHelpers.toConsumableArray(document.body.querySelectorAll(".landing-main")),babelHelpers.toConsumableArray(document.body.querySelectorAll(".landing-footer")))}))}},{key:"createInsertBlockButton",value:function e(t){var n=new BX.Landing.UI.Button.Plus("insert_first_block",{text:o.Loc.getMessage("ACTION_BUTTON_CREATE")});n.on("click",this.showBlocksPanel.bind(this,null,t,n));n.on("mouseover",this.onCreateButtonMouseover.bind(this,t,n));n.on("mouseout",this.onCreateButtonMouseout.bind(this,t,n));return n}},{key:"onCreateButtonMouseover",value:function e(t,n){if(r.Dom.hasClass(t,"landing-header")||r.Dom.hasClass(t,"landing-footer")){var a=this.getLayoutAreas();if(a.length>1){var i=o.Loc.getMessage("ACTION_BUTTON_CREATE");if(r.Dom.hasClass(t,"landing-main")){n.setText("".concat(i," ").concat(o.Loc.getMessage("LANDING_ADD_BLOCK_TO_MAIN")))}if(r.Dom.hasClass(t,"landing-header")){n.setText("".concat(i," ").concat(o.Loc.getMessage("LANDING_ADD_BLOCK_TO_HEADER")))}if(r.Dom.hasClass(t,"landing-sidebar")){n.setText("".concat(i," ").concat(o.Loc.getMessage("LANDING_ADD_BLOCK_TO_SIDEBAR")))}if(r.Dom.hasClass(t,"landing-footer")){n.setText("".concat(i," ").concat(o.Loc.getMessage("LANDING_ADD_BLOCK_TO_FOOTER")))}clearTimeout(this.fadeTimeout);this.fadeTimeout=setTimeout((function(){r.Dom.addClass(t,"landing-area-highlight");a.filter((function(e){return e!==t})).forEach((function(e){r.Dom.addClass(e,"landing-area-fade")}))}),400)}}}},{key:"onCreateButtonMouseout",value:function e(t,n){clearTimeout(this.fadeTimeout);if(r.Dom.hasClass(t,"landing-header")||r.Dom.hasClass(t,"landing-footer")){var a=this.getLayoutAreas();if(a.length>1){n.setText(o.Loc.getMessage("ACTION_BUTTON_CREATE"));a.forEach((function(e){r.Dom.removeClass(e,"landing-area-highlight");r.Dom.removeClass(e,"landing-area-fade")}))}}}},{key:"initEmptyArea",value:function e(t){if(t){t.innerHTML="";r.Dom.append(this.createInsertBlockButton(t).layout,t);r.Dom.addClass(t,"landing-empty")}}},{key:"destroyEmptyArea",value:function e(t){if(t){var n=t.querySelector('button[data-id="insert_first_block"]');if(n){r.Dom.remove(n)}r.Dom.removeClass(t,"landing-empty")}}},{key:"adjustEmptyAreas",value:function e(){this.getLayoutAreas().filter((function(e){return d(e)&&u(e)})).forEach(this.destroyEmptyArea,this);this.getLayoutAreas().filter((function(e){return!d(e)&&!u(e)})).forEach(this.initEmptyArea,this);var t=document.body.querySelector("main.landing-edit-mode");var n=!this.getLayoutAreas().some(d);if(t){if(n){r.Dom.addClass(t,"landing-empty");return}r.Dom.removeClass(t,"landing-empty")}}},{key:"enableControls",value:function e(){r.Dom.removeClass(document.body,"landing-ui-hide-controls")}},{key:"disableControls",value:function e(){r.Dom.addClass(document.body,"landing-ui-hide-controls")}},{key:"isControlsEnabled",value:function e(){return!r.Dom.hasClass(document.body,"landing-ui-hide-controls")}},{key:"makeControlsInternal",value:function e(){BX.onCustomEvent("BX.Landing.Main:changeControls",["internal",t.topInPercent()]);r.Dom.removeClass(document.body,"landing-ui-external-controls")}},{key:"makeControlsExternal",value:function e(){BX.onCustomEvent("BX.Landing.Main:changeControls",["external",t.topInPercent()]);r.Dom.addClass(document.body,"landing-ui-external-controls")}},{key:"isControlsExternal",value:function e(){return r.Dom.hasClass(document.body,"landing-ui-external-controls")}},{key:"setDeviceCode",value:function e(t){document.body.setAttribute("data-device",t)}},{key:"getDeviceCode",value:function e(){return document.body.getAttribute("data-device")}},{key:"setTouchDevice",value:function e(){r.Dom.removeClass(document.documentElement,"bx-no-touch");r.Dom.addClass(document.documentElement,"bx-touch")}},{key:"setNoTouchDevice",value:function e(){r.Dom.removeClass(document.documentElement,"bx-touch");r.Dom.addClass(document.documentElement,"bx-no-touch")}},{key:"appendBlock",value:function e(t,n){var o=r.Tag.render(F||(F=babelHelpers.taggedTemplateLiteral(["",""])),t.content);o.id="block".concat(t.id);if(!n){r.Dom.addClass(o,"landing-ui-show");f(o,"showBlock").then((function(){r.Dom.removeClass(o,"landing-ui-show")}))}this.insertToBlocksFlow(o);return o}},{key:"showBlocksPanel",value:function e(t,n,o,a){this.currentBlock=t;this.currentArea=n;this.insertBefore=a;BX.Landing.UI.Panel.EditorPanel.getInstance().hide();if(this.isCrmFormPage()||this.isControlsExternal()){var i=s.PageObject.getRootWindow();r.Dom.append(this.getBlocksPanel().layout,i.document.body);r.Dom.append(this.getBlocksPanel().overlay,i.document.body)}this.getBlocksPanel().show();this.disableAddBlockButtons();if(!!n&&!!o){this.onCreateButtonMouseout(n,o)}}},{key:"showSaveBlock",value:function e(t){this.currentBlock=t;this.getSaveBlockPanel().show()}},{key:"disableAddBlockButtons",value:function e(){s.PageObject.getBlocks().forEach((function(e){var t=e.panels.get("create_action");if(t){var n=t.buttons.get("insert_after");if(n){n.disable()}}}))}},{key:"enableAddBlockButtons",value:function e(){s.PageObject.getBlocks().forEach((function(e){var t=e.panels.get("create_action");if(t){var n=t.buttons.get("insert_after");if(n){n.enable()}}}))}},{key:"createBlocksPanel",value:function e(){var t=this;var n=this.options.blocks;var i=Object.keys(n);var l=new a.Content("blocks_panel",{title:o.Loc.getMessage("LANDING_CONTENT_BLOCKS_TITLE"),className:"landing-ui-panel-block-list",scrollAnimation:true});l.subscribe("onCancel",(function(){t.enableAddBlockButtons()}));i.forEach((function(e){var o=!k(n[e].items);var a=e==="popular";var i=n[e].separator;if(o&&!a||i){l.appendSidebarButton(t.createBlockPanelSidebarButton(e,n[e]))}}));l.appendSidebarButton(new BX.Landing.UI.Button.SidebarButton("feedback_button",{className:"landing-ui-button-sidebar-feedback",text:o.Loc.getMessage("LANDING_BLOCKS_LIST_FEEDBACK_BUTTON"),onClick:this.showFeedbackForm.bind(this)}));return l}},{key:"showSliderFeedbackForm",value:function e(){var n=this;r.Runtime.loadExtension("ui.feedback.form").then((function(){var e={};e.bitrix24=n.options.server_name;e.siteId=n.options.site_id;e.siteUrl=n.options.url;e.siteTemplate=n.options.xml_id;e.productType=n.options.productType||"Undefined";e.typeproduct=function(){if(n.options.params.type===t.TYPE_GROUP){return"KNOWLEDGE_GROUP"}return n.options.params.type}();BX.UI.Feedback.Form.open({id:Math.random()+"",forms:n.getFeedbackFormOptions(),presets:e})}))}},{key:"getFeedbackFormOptions",value:function e(){return[{zones:["en","eu","in","uk"],id:16,lang:"en",sec:"3h483y"},{zones:["ru","by","kz"],id:8,lang:"ru",sec:"x80yjw"},{zones:["ua"],id:18,lang:"ua",sec:"d9e09o"},{zones:["la","co","mx"],id:14,lang:"la",sec:"wu561i"},{zones:["de"],id:10,lang:"de",sec:"eraz2q"},{zones:["com.br","br"],id:12,lang:"br",sec:"r6wvge"}]}},{key:"onSliderFormLoaded",value:function e(){this.sliderFormLoader.hide()}},{key:"showFeedbackForm",value:function e(){this.showSliderFeedbackForm({target:"blocksList"})}},{key:"initFeedbackForm",value:function e(){var t=s.PageObject.getRootWindow();(function(e,t,n,o){e.Bitrix24FormObject=o;e[o]=e[o]||function(){arguments[0].ref=n;(e[o].forms=e[o].forms||[]).push(arguments[0])};if(e[o].forms)return;var a=t.createElement("script");var i=1*new Date;a.async=1;a.src="".concat(n,"?").concat(i);var l=t.getElementsByTagName("script")[0];l.parentNode.insertBefore(a,l)})(t,t.document,"https://product-feedback.bitrix24.com/bitrix/js/crm/form_loader.js","b24formFeedBack")}},{key:"createBlockPanelSidebarButton",value:function e(t,n){return new BX.Landing.UI.Button.SidebarButton(t,{text:n.name,child:!n.separator,className:n["new"]?"landing-ui-new-section":"",onClick:this.onBlocksListCategoryChange.bind(this,t)})}},{key:"addNewBlockToCategory",value:function e(t,n){if(this.blocks[t]){var o=n["codeOriginal"]||n["code"];if(t==="last"){if(!this.lastBlocks){this.lastBlocks=Object.keys(this.blocks.last.items)}this.lastBlocks.unshift(o)}else{this.blocks[t].items[o]=n}this.onBlocksListCategoryChange(t)}}},{key:"removeBlockFromList",value:function e(t){var n=false;for(var o in this.blocks){if(this.blocks[o].items[t]!==undefined){delete this.blocks[o].items[t];n=true}}if(this.lastBlocks.indexOf(t)!==-1){this.lastBlocks.splice(this.lastBlocks.indexOf(t),1);n=true}if(n){var a=this.getBlocksPanel().sidebarButtons.find((function(e){return r.Dom.hasClass(e.layout,"landing-ui-active")}));if(a){this.onBlocksListCategoryChange(a.id)}}}},{key:"getTemplateCode",value:function e(){var t=n.Env.getInstance().getOptions(),o=t.tplCode;if(o.indexOf("@")>0){o=o.split("@")[1]}if(!o||o.length<=0){o=null}return o}},{key:"onBlocksListCategoryChange",value:function e(t){var n=this;var o=this.getTemplateCode();this.getBlocksPanel().content.hidden=false;this.getBlocksPanel().sidebarButtons.forEach((function(e){var n=e.id===t?"add":"remove";e.layout.classList[n]("landing-ui-active")}));this.getBlocksPanel().content.innerHTML="";if(t==="last"){if(!this.lastBlocks){this.lastBlocks=Object.keys(this.blocks.last.items)}this.lastBlocks=babelHelpers.toConsumableArray(new Set(this.lastBlocks));this.lastBlocks.forEach((function(e){var t=n.getBlockFromRepository(e);n.getBlocksPanel().appendCard(n.createBlockCard(e,t))}));return}Object.keys(this.blocks[t].items).forEach((function(e){var a=n.blocks[t].items[e];var i=a["tpl_code"]&&a["tpl_code"].length>0?a["tpl_code"]:null;if(!o||!i||i&&i===o){n.getBlocksPanel().appendCard(n.createBlockCard(e,a))}}));if(this.getBlocksPanel().content.scrollTop){requestAnimationFrame((function(){n.getBlocksPanel().content.scrollTop=0}))}}},{key:"getBlockFromRepository",value:function e(t){var n=this.options.blocks;var o=Object.keys(n);var a=o.find((function(e){return t in n[e].items}));if(a){return n[a].items[t]}}},{key:"onCopyBlock",value:function e(t){window.localStorage.landingBlockId=t.id;window.localStorage.landingBlockName=t.manifest.block.name;window.localStorage.landingBlockAction="copy";try{window.localStorage.requiredUserAction=JSON.stringify(t.requiredUserActionOptions)}catch(e){window.localStorage.requiredUserAction=""}}},{key:"onCutBlock",value:function e(t){window.localStorage.landingBlockId=t.id;window.localStorage.landingBlockName=t.manifest.block.name;window.localStorage.landingBlockAction="cut";try{window.localStorage.requiredUserAction=JSON.stringify(t.requiredUserActionOptions)}catch(e){window.localStorage.requiredUserAction=""}BX.Landing.PageObject.getBlocks().remove(t);r.Dom.remove(t.node);BX.onCustomEvent("Landing.Block:onAfterDelete",[t])}},{key:"onPasteBlock",value:function e(t,n){var o=this;if(window.localStorage.landingBlockId){var a="Landing::copyBlock";if(window.localStorage.landingBlockAction==="cut"){a="Landing::moveBlock"}var i={};i[a]={action:a,data:{lid:t.lid||BX.Landing.Main.getInstance().id,block:window.localStorage.landingBlockId,params:{AFTER_ID:t.id,RETURN_CONTENT:"Y"}}};BX.Landing.Backend.getInstance().batch(a,i,{action:a}).then((function(e){o.currentBlock=t;return o.addBlock(e[a].result.content,false,false,n)}))}}},{key:"addBlock",value:function e(t,n){var o=arguments.length>3?arguments[3]:undefined;if(this.lastBlocks){this.lastBlocks.unshift(t.manifest.codeOriginal||t.manifest.code)}var a=this;var i=this.appendBlock(t,n);return this.loadBlockDeps(t).then((function(e){a.currentBlock=null;a.currentArea=null;var n=parseInt(t.id);var l=BX.Landing.PageObject.getBlocks().get(n);if(l){r.Dom.remove(l.node);BX.Landing.PageObject.getBlocks().remove(l)}void new BX.Landing.Block(i,{id:n,sections:t.sections,requiredUserAction:t.requiredUserAction,manifest:t.manifest,access:t.access,active:r.Text.toBoolean(t.active),php:t.php,designed:t.designed,anchor:t.anchor,dynamicParams:t.dynamicParams,repoId:t.repoId});return a.runBlockScripts(t).then((function(){if(o){o(n)}return i}))}))["catch"]((function(e){console.warn(e)}))}},{key:"onAddBlock",value:function e(t,n){var o=this;var a=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;var i=r.Text.toNumber(n);this.hideBlocksPanel();return this.showBlockLoader().then(this.loadBlock(t,i,a)).then((function(e){return new Promise((function(t){setTimeout((function(){t(e)}),500)}))})).then((function(e){e.manifest.codeOriginal=t;var n=o.addBlock(e,false,o.insertBefore);o.insertBefore=false;o.adjustEmptyAreas();void o.hideBlockLoader();o.enableAddBlockButtons();BX.onCustomEvent("BX.Landing.Block:onAfterAdd",e);return n}))}},{key:"insertToBlocksFlow",value:function e(t){var n=this.currentBlock&&this.currentBlock.node&&this.currentBlock.node.parentNode;if(n&&!this.insertBefore){r.Dom.insertAfter(t,this.currentBlock.node);return}if(n&&this.insertBefore){r.Dom.insertBefore(t,this.currentBlock.node)}r.Dom.prepend(t,this.currentArea)}},{key:"getBlockLoader",value:function e(){if(!this.blockLoader){this.blockLoader=new BX.Loader({size:60});this.blockLoaderContainer=r.Dom.create("div",{props:{className:"landing-block-loader-container"},children:[this.blockLoader.layout]})}return this.blockLoaderContainer}},{key:"showBlockLoader",value:function e(){this.insertToBlocksFlow(this.getBlockLoader());this.blockLoader.show();return Promise.resolve()}},{key:"hideBlockLoader",value:function e(){r.Dom.remove(this.getBlockLoader());this.blockLoader=null;return Promise.resolve()}},{key:"loadBlockDeps",value:function e(t){var n=this;var o=BX.processHTML(t.content_ext);if(BX.type.isArray(o.SCRIPT)){o.SCRIPT=o.SCRIPT.filter((function(e){return!e.isInternal}))}var a=0;var i=t.js.length+o.SCRIPT.length+o.STYLE.length+t.css.length;var l=null;if(!this.loadedDeps[t.manifest.code]&&i>0){l=new Promise((function(e){function l(){a+=1;if(a===i){e(t)}}if(i>a){o.SCRIPT.forEach((function(e){if(!e.isInternal){BX.loadScript(e.JS,l)}}));o.STYLE.forEach((function(e){BX.loadScript(e,l)}));t.css.forEach((function(e){BX.loadScript(e,l)}));t.js.forEach((function(e){BX.loadScript(e,l)}))}else{l()}n.loadedDeps[t.manifest.code]=true}))}else{l=Promise.resolve(t)}return l}},{key:"runBlockScripts",value:function e(t){return new Promise((function(e){var n=BX.processHTML(t.content).SCRIPT;if(n.length){BX.ajax.processScripts(n,undefined,(function(){e(t)}))}else{e(t)}}))}},{key:"loadBlock",value:function e(t,n,o){var a=this;return function(){var e=a.id;var i=a.options.site_id;if(a.currentBlock){e=a.currentBlock.lid;i=a.currentBlock.siteId}if(a.currentArea){e=r.Dom.attr(a.currentArea,"data-landing");i=r.Dom.attr(a.currentArea,"data-site")}var l={lid:e,siteId:i,preventHistory:o?1:0};var s={ACTIVE:"Y",CODE:t,AFTER_ID:a.currentBlock?a.currentBlock.id:0,RETURN_CONTENT:"Y"};if(!r.Type.isBoolean(o)||o===false){BX.Landing.History.getInstance().push()}if(!n){l.fields=s;return c.Backend.getInstance().action("Landing::addBlock",l,{code:t}).then((function(t){if(a.insertBefore){return c.Backend.getInstance().action("Landing::upBlock",{lid:e,siteId:i,block:t.id}).then((function(){return t}))}return t}))}return BX.Landing.Backend.getInstance().action("Block::getContent",{block:n,lid:e,fields:s,editMode:1}).then((function(e){e.id=n;return e}))}}},{key:"createBlockCard",value:function e(t,n,o){return new BX.Landing.UI.Card.BlockPreviewCard({title:n.name,image:n.preview,code:t,app_expired:n.app_expired,favorite:!!n.favorite,favoriteMy:!!n.favoriteMy,repo_id:n.repo_id,mode:o,isNew:n["new"]===true,onClick:this.onAddBlock.bind(this,t)})}},{key:"onBlockDelete",value:function e(t){if(!t.parent.querySelector(".block-wrapper")){this.adjustEmptyAreas()}}},{key:"showOverlay",value:function e(){var t=document.querySelector("main.landing-edit-mode");if(t){r.Dom.addClass(t,"landing-ui-overlay")}}},{key:"hideOverlay",value:function e(){var t=document.querySelector("main.landing-edit-mode");if(t){r.Dom.removeClass(t,"landing-ui-overlay")}}},{key:"reloadSlider",value:function e(t){return l.SliderHacks.reloadSlider(t,window.parent)}}]);return t}(t.EventEmitter);babelHelpers.defineProperty(H,"TYPE_PAGE","PAGE");babelHelpers.defineProperty(H,"TYPE_STORE","STORE");babelHelpers.defineProperty(H,"TYPE_KNOWLEDGE","KNOWLEDGE");babelHelpers.defineProperty(H,"TYPE_GROUP","GROUP");e.Main=H})(this.BX.Landing=this.BX.Landing||{},BX.Event,BX.Landing,BX.Landing,BX.Landing.UI.Panel,BX.Landing.UI.Panel,BX.Landing,BX.Landing,BX,BX.Landing);
//# sourceMappingURL=main.bundle.map.js